package project;

import java.time.*;
import java.time.temporal.TemporalAdjusters;

public class DaylightSavingTime {

    public static void main(String[] args) {
        // 春季时间转换
        LocalDateTime springTime = LocalDateTime.of(2024, Month.MARCH, 10, 2, 0);
        ZonedDateTime springTransition = springTime.atZone(ZoneId.of("UTC"));
        ZonedDateTime adjustedSpringTime = springTransition.plusHours(1);
        System.out.println("Spring transition: " + springTransition + " -> " + adjustedSpringTime);

        // 秋季时间转换
        LocalDateTime autumnTime = LocalDateTime.of(2024, Month.NOVEMBER, 3, 2, 59, 59);
        ZonedDateTime autumnTransition = autumnTime.atZone(ZoneId.of("UTC"));
        ZonedDateTime adjustedAutumnTime = autumnTransition.withZoneSameInstant(ZoneId.of("UTC")).with(TemporalAdjusters.previous(DayOfWeek.SUNDAY)).withHour(2).withMinute(0).withSecond(0);
        System.out.println("Autumn transition: " + autumnTransition + " -> " + adjustedAutumnTime);
    }
}

